<template>
    <div>
      <tr>
        <td>名称</td>
        <td><input type="text" v-model="text"></td>
      </tr>
      <tr>
        <td>价格</td>
        <td><input type="text" v-model="price"></td>
      </tr>
      <tr>
        <td>图片</td>
        <td><input type="file" id="img"></td>
      </tr>
      <button @click="add">添加</button>
    </div>
</template>

<script>
    export default {
        name: "addgoods",
      data:function () {
        return{
          text:'',
          price:'',
        }
      },
      methods:{
          add:function () {
            let formdata = new FormData();
            formdata.append('text', this.text);
            formdata.append('price', this.price);
            let img = document.getElementById('img').files[0];
            formdata.append('img', img, img.name);
            this.axios({
              url:'http://127.0.0.1:8000/addgoods/',
              method:'post',
              data:formdata
            }).then(res=>{
                if(res.data.code==200){
                  console.log(res.data.message)
                }else {
                  console.log(res.data.message)
                }
            })
          }
      }
    }
</script>

<style scoped>

</style>
